
namespace gen {

	template <class FunctorT, class LimitsT>
	template <typename IteratorT>
	class find_in_expr<FunctorT,LimitsT>::find_in_expr_initializator 
	{
	private:
		IteratorT m_reference;
		FunctorT m_expr;
		
	public:
		find_in_expr_initializator( FunctorT const& expr, IteratorT const& reference )
		: m_expr(expr), m_reference(reference)
		{}

		template <class IteratorT2>
		bool operator()(IteratorT2 const& i)
		{
			return m_expr(m_reference, i);
		}
	};

	template <class FunctorT, class LimitsT>
	template <typename GeneratorT, typename InfoT>
	void 
	find_in_expr<FunctorT,LimitsT>::compute(GeneratorT const& g, InfoT & f) const
	{
		typedef typename LimitsT::iterator_t		iterator_t;
		typedef typename LimitsT::context_t			context_t;
		typedef typename context_t::multi_domain_t	multi_domain_t;
		typedef find_in_expr_initializator<typename InfoT::iterator_t>
													initializator_t;
		iterator_t i;
		iterator_t first = lim.first(f);
		iterator_t last = lim.last(f);
		initializator_t init(expr, f.current());
		context_t tmp(first, last, f, init);
		multi_domain_t & domain = tmp.domain();

		for (i = domain.firstPositive(); i != domain.lastPositive(); ++i)
        {
			if (domain.point(i))
			{
				tmp.current(i);
				g.generate(tmp);
			}
        }
	}


	template <class T, class ContextT>
	inline find_in_expr< T, limits<ContextT> >
	find_in_g(const T & f, limits<ContextT> const& l)
	{
		return find_in_expr<T, limits<ContextT> >(f, l);
	}

}
